package com.market.manager;

import java.util.List;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.market.domain.Message;
import com.market.domain.Order;
import com.market.domain.Role;
import com.market.domain.User;

public interface UserManager extends GenericManager<User, Long>  {
	/**
	 * load all roles are associated with this user
	 * @param user
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, readOnly=true)
	public List<Role> fetchRoles(User user);
	
	/**
	 * load all Messages are associated with this user
	 * @param user
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED,readOnly=true)
	public List<Message> fetchMessages(User user);
	
	/**
	 * load all Order are associated with this user
	 * @param user
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED,readOnly=true)
	public List<Order> fetchOrders(User user);
	
	/**
	 * Load user info by specify user's email and password
	 * Usually use for user login
	 * @param user
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, readOnly=true)
	public User fetchByEmailAndPassword(String email, String password);
	
	/**
	 * Load user by specific email
	 * @param email
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED,readOnly=true)
	public User fetchByEmail(String email);
	
	
	/**
	 * Login user by specific user's email, because have to save user activity
	 * records, so readonly have to be set to false
	 * @param email
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED,readOnly=false)
	public User loginByEmail(User user);
	
	/**
	 * Load user by specific telephone number
	 * @param telephone
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, readOnly=true)
	public User fetchByTelephone(String telephone);
	
	/**
	 * Login user by specific user's telephone number, because have to save user activity
	 * records, so readonly have to be set to false
	 * @param telephone
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, readOnly=false)
	public User loginByTelephone(User user);
	
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class)
	public User activateAccount(Long id, String activatedCode);
}
